﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Abp.Domain.Repositories;
using Abp.Domain.Services;
using Abp.UI;
using FwProject.ShoppingMall.EventAdvertising;

namespace FwProject.AppManager
{
    public class NoticeManager: IDomainService
    {
        private readonly IRepository<Notice, Guid> _repositoryNotice;

        public NoticeManager(IRepository<Notice, Guid> repositoryNotice)
        {
            _repositoryNotice = repositoryNotice;

        }

        /// <summary>
        /// 创建一个公告
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<Guid> CreateNotice(Notice model)
        {
            var data = _repositoryNotice.GetAll().Where(o => o.NoticeName == model.NoticeName).FirstOrDefault();
            if (data != null)
                throw new UserFriendlyException("该公告字已存在！");

            return await _repositoryNotice.InsertAndGetIdAsync(model);
        }
        /// <summary>
        /// 编辑一个公告
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task UpdateNotice(Notice model)
        {
            await _repositoryNotice.UpdateAsync(model);
        }
        /// <summary>
        /// 删除一个公告
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task DeleteNotice(Notice model)
        {
            await _repositoryNotice.DeleteAsync(model);
        }
    }
}
